<?php
/*
	$Id: admincp_contribute.php 12844 2012-08-21 gy $
*/

if(!defined('IN_UCHOME') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

//权限
if(!$allowmanage = checkperm('managerelease')) {
	cpmessage('no_authority_management_operation');
}


if(isset($_POST['tcheck'])){
	$tid = intval($_POST['tid']);
	$tcheck = intval($_POST['tcheck']);
	updatetable('contribute_type', array('tcheck'=>$tcheck), array('tid'=>$tid));
	cpmessage('do_success', 'admincp.php?ac=release');
}

if(!empty($_POST['tedit'])){
	$tid = intval($_POST['tid']);
	$type = trim($_POST['type']);
	$tcont = trim($_POST['tcont']);
	$tcheck = 0;
	updatetable('contribute_type', array('type'=>$type,'tcont'=>$tcont,'tcheck'=>$tcheck), array('tid'=>$tid));
	cpmessage('do_success', 'admincp.php?ac=release');
}

if(!empty($_POST['tadd'])){
	$data['uid'] = $_SGLOBAL['supe_uid'];
	$data['type'] = trim($_POST['type']);
	$data['tcont'] = trim($_POST['tcont']);
	$data['time'] = time();
	$insert = inserttable('contribute_type',$data,1);
	if($insert){
		cpmessage('release_success', 'admincp.php?ac=release');
	}else{
		cpmessage('release_fail', 'admincp.php?ac=release');
	}
}

if($_GET['op'] == 'tadd'){
	if(!$allowmanage){cpmessage('no_authority_management_operation');}
	$actives = array('tadd' => 'class="active"');
}elseif($_GET['op'] == 'topen'){
	if(!$allowmanage){cpmessage('no_authority_management_operation');}
	$tid = intval($_GET['tid']);
	$isopen = 0;
	updatetable('contribute_type', array('isopen'=>$isopen), array('tid'=>$tid));
	cpmessage('do_success', 'admincp.php?ac=release');
}elseif($_GET['op'] == 'tclose'){
	if(!$allowmanage){cpmessage('no_authority_management_operation');}
	$tid = intval($_GET['tid']);
	$isopen = 1;
	updatetable('contribute_type', array('isopen'=>$isopen), array('tid'=>$tid));
	cpmessage('do_success', 'admincp.php?ac=release');
}elseif($_GET['op'] == 'tcheck') {	
	if(!$allowmanage){cpmessage('no_authority_management_operation');}
	if(!empty($_GET['tid'])){$actives = array('tcheck' => 'class="active"');}
	$tid = intval($_GET['tid']);
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('contribute_type')."  WHERE tid =".$tid);
	$cont_look = $_SGLOBAL['db']->fetch_array($query);
}elseif($_GET['op'] == 'tedit') {	
	if(!$allowmanage){cpmessage('no_authority_management_operation');}
	if(!empty($_GET['tid'])){$actives = array('tedit' => 'class="active"');}
	$tid = intval($_GET['tid']);
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('contribute_type')."  WHERE tid =".$tid);
	$cont_look = $_SGLOBAL['db']->fetch_array($query);
}else {
		
	$mpurl = 'admincp.php?ac=release';
	
	//处理搜索
	$intkeys = array('uid', 'uid');
	$strkeys = array();
	$randkeys = array(array('sstrtotime','time'));
	$likekeys = array();
	$results = getwheres($intkeys, $strkeys, $randkeys, $likekeys);
	$wherearr = $results['wherearr'];
	$wheresql = empty($wherearr)?'1':implode(' AND ', $wherearr);
	$mpurl .= '&'.implode('&', $results['urls']);
	
	//排序
	$orders = getorders(array('time'), 'tid');
	$ordersql = $orders['sql'];
	if($orders['urls']) $mpurl .= '&'.implode('&', $orders['urls']);
	$orderby = array($_GET['orderby']=>' selected');
	$ordersc = array($_GET['ordersc']=>' selected');
	
	//激活
	if(empty($_GET['tid'])) {
		$actives = array('all' => 'class="active"');
	}
	
	$perpage = empty($_GET['perpage'])?0:intval($_GET['perpage']);
	if(!in_array($perpage, array(20,50,100))) $perpage = 20;
	
	$page = empty($_GET['page'])?1:intval($_GET['page']);
	if($page<1) $page = 1;
	$start = ($page-1)*$perpage;
	//检查开始数
	ckstart($start, $perpage);

	$count = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM ".tname('contribute_type')." WHERE $wheresql"), 0);
	$selectsql = '*';

	$mpurl .= '&perpage='.$perpage;
	$perpages = array($perpage => ' selected');
	
	$list = array();
	$multi = '';
	$managebatch = checkperm('admin');
	$allowbatch = true;
	if($count) {
		
		$query = $_SGLOBAL['db']->query("SELECT $selectsql FROM ".tname('contribute_type')." WHERE $wheresql $ordersql LIMIT $start,$perpage");
		while ($value = $_SGLOBAL['db']->fetch_array($query)) {
			$list[] = $value;
		}
		$multi = multi($count, $perpage, $page, $mpurl);
	}
}

?>